<template>
  <div class="mod-log">
    <el-form :inline="true" :model="searchForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="searchForm.key" placeholder="日志时间" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    
    <el-tables 
      :selecionType='selecionType'
      :table-data="dataList"
      :table-label="tableLabel"
      @handleSelectionChange="handleSelectionChange"
      >
    </el-tables>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  import { formatTimeToStr } from '@/utils'
  export default {
    data () {
      return {
        tableLabel: [
          { label: '日志时间',
            param: 'logTime',
            align: 'center',
            sortable: false,
            render: (row) => {
              return formatTimeToStr(row.logTime, 'yyyy-MM-dd')
            }
          },
          { label: '系统健康检查信息内容', param: 'logContents', align: 'center', isShow: true }
        ],
        selecionType: 'index',
        searchForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        selectionDataList: []
      }
    },
    created () {
      this.getDataList()
    },
    components: {
      'ElTables': () => import('@/components/el-table')
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.$http({
          url: '/user/updownlog/list',
          method: 'get',
          params: {
            'page': this.pageIndex,
            'limit': this.pageSize,
            'name': this.searchForm.key
          }
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.records
            this.totalPage = data.page.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      handleSelectionChange (val) {
      }
    }
  }
</script>
